package Demo;

import java.util.ArrayList;
import java.util.Iterator;

public class CollectionDemo {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student s1= new Student("小明",20);
        Student s2= new Student("小蛤",22);
        Student s3= new Student("小感",23);

        list.add(s1);
        list.add(s2);
        list.add(s3);

        // 迭代器的方式进行遍历
        Iterator<Student> it = list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("----------------------------");
        // 增强for
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
